home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 37 / Amiga Format CD37 (1999-02-16)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-03].iso / -screenplay- / shareware / invasionforce / source / map_editor2.c < prev    next >
C/C++ Source or Header  |  1999-01-09  |  19KB  |  568 lines

  1. /*
  2.    map_editor2.c -- map editor module for Invasion Force
  3.    This module provides the Invasion Force map editor.
  4.    This source code is free.  You may make as many copies as you like.
  5. */
  6.  
  7. // standard header for all program modules
  8. #include "global.h"
  9. #include "gadgets_protos.h"
  10.  
  11. int myctr[] = {
  12.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  13. };
  14.  
  15.  
  16.  
  17.  
  18. void do_stats_window()
  19. {  // everything for the stats window
  20.    struct Window *stats_window = NULL;
  21.    struct Gadget *context, *ok_gad;
  22.    struct NewGadget generic = {
  23.       515,25,      // leftedge, topedge
  24.       66,16,   // width, height
  25.       "Okay",  // text label
  26.       NULL,    // font
  27.       3,       // gadget ID
  28.       NULL,NULL,NULL
  29.    };
  30.    int tot_hex, ctr, ctx, cty;
  31.    static int z, pcx, pcz;
  32.    static float pcy; 
  33.    
  34.    int myctr[] = {
  35.        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  36.    };
  37.     
  38.    // make sure user doesn't play with the map window now
  39.    SetPointer(map_window,BUSY_POINTER);
  40.    ModifyIDCMP(map_window,NULL);
  41.  
  42.    // create the gadgets
  43.    if (!CreateContext(&context))
  44.       clean_exit(1,"Unable to create context gadget!");
  45.    generic.ng_VisualInfo = vi;
  46.    generic.ng_TextAttr = &topaz11bold;
  47.    generic.ng_LeftEdge += 5;
  48.    generic.ng_GadgetText = "OK";
  49.    ok_gad = CreateGadget(BUTTON_KIND,context,&generic,TAG_END);
  50.  
  51.    // do the window itself
  52.    stats_window = OpenWindowTags(NULL,
  53.       WA_Gadgets,context,
  54.       WA_Title,"Map Statistics",
  55.       WA_Top,90,    WA_Left,7,
  56.       WA_Width,612,  WA_Height,300,
  57.       WA_IDCMP,IDCMP_VANILLAKEY|IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_GADGETUP,
  58.       WA_Flags,NOCAREREFRESH|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_CLOSEGADGET,
  59.       WA_CustomScreen,map_screen,
  60.       TAG_END );
  61.    if (stats_window==NULL)
  62.       clean_exit(1,"ERROR: Unable to open stats window!");
  63.    rast_port = stats_window->RPort;
  64.  
  65.    tot_hex = width * height; 
  66.    sprintf(foo,"Total number of hexes: %ld",tot_hex);
  67.    plot_text(5+15,16,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  68.    sprintf(foo,"Total of each terrain type:");
  69.    plot_text(5+130,28,foo,WHITE,LT_GRAY,JAM2,&topaz11);
  70.     
  71.    for (ctr = 0; ctr<=15; ctr++) {
  72.        SetAPen(rast_port,BLACK);
  73.        if (terrain_index[ctr]<9) {
  74.            px_outline_hex(5+30,40+32*ctr);
  75.            px_plot_hex(5+30,40+32*ctr,terrain_index[ctr]);
  76.        FI
  77.        if (terrain_index[ctr]>=9 && terrain_index[ctr] <16) {
  78.            px_outline_hex(5+260,40+32*(ctr-8)); 
  79.            px_plot_hex(5+260,40+32*(ctr-8),terrain_index[ctr]);
  80.        FI
  81.    OD
  82.    // blit in the city
  83.    px_outline_hex(5+260,264);
  84.    px_plot_hex(5+260,264,HEX_PLAINS);
  85.    px_plot_city(272,272);
  86.  
  87.    bevel_box(70,40,190,255,TRUE);
  88.    bevel_box(300,40,190,255,TRUE);
  89.  
  90.    for (ctx = 0; ctx<=width; ctx++) {
  91.        for (cty = 0; cty<=height; cty++) {
  92.            switch (get(t_grid,ctx-1,cty-1)) {
  93.                 case HEX_FORBID:
  94.                     myctr[0]++;
  95.                     break;
  96.                 case HEX_PLAINS:
  97.                     myctr[1]++;
  98.                     break;
  99.                 case HEX_DESERT:
  100.                     myctr[2]++;
  101.                     break;
  102.                 case HEX_BRUSH:
  103.                     myctr[3]++;
  104.                     break;
  105.                 case HEX_FOREST:
  106.                     myctr[4]++;
  107.                     break;
  108.                 case HEX_JUNGLE:
  109.                     myctr[5]++;
  110.                     break;
  111.                 case HEX_RUGGED:
  112.                     myctr[6]++;
  113.                     break;
  114.                 case HEX_HILLS:
  115.                     myctr[7]++;
  116.                     break;
  117.                 case HEX_MOUNTAINS:
  118.                     myctr[8]++;
  119.                     break;
  120.                 case HEX_PEAKS:
  121.                     myctr[9]++;
  122.                     break;
  123.                 case HEX_SWAMP:
  124.                     myctr[10]++;
  125.                     break;
  126.                 case HEX_SHALLOWS:
  127.                     myctr[11]++;
  128.                     break;
  129.                 case HEX_OCEAN:
  130.                     myctr[12]++;
  131.                     break;
  132.                 case HEX_DEPTH:
  133.                     myctr[13]++;
  134.                     break;
  135.                 case HEX_ICE:
  136.                     myctr[14]++;
  137.            }         
  138.            if (city_hereP(ctx,cty))
  139.                 myctr[15]++;
  140.        OD
  141.    OD
  142.         
  143.    sprintf(foo,"%ld",myctr[0]);
  144.    plot_text(5+70,52,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  145.    z = width * height;
  146.    pcx = (100 * myctr[0]) / z;
  147.    pcy = (100 * myctr[0]) % z;
  148.    pcz = pcx + pcy;
  149.    sprintf(foo,"%ld",pcx);
  150.    strcat(foo,"%");
  151.    plot_text(5+110,52,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  152.    sprintf(foo,"%ld",myctr[1]);
  153.    plot_text(5+70,85,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  154.    z = width * height;
  155.    pcx = (100 * myctr[1]) / z;
  156.    //pct += (100 * myctr[1]) % z;
  157.    sprintf(foo,"%ld",pcx);
  158.    strcat(foo,"%");
  159.    plot_text(5+110,85,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  160.    sprintf(foo,"%ld",myctr[2]);
  161.    plot_text(5+70,118,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  162.    z = width * height;
  163.    pcx = (100 * myctr[2]) / z;
  164.    //pct += (100 * myctr[2]) % z;
  165.    sprintf(foo,"%ld",pcx);
  166.    strcat(foo,"%");
  167.    plot_text(5+110,118,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  168.    sprintf(foo,"%ld",myctr[3]);
  169.    plot_text(5+70,150,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  170.    z = width * height;
  171.    pcx = (100 * myctr[3]) / z;
  172.    sprintf(foo,"%ld",pcx);
  173.    strcat(foo,"%");
  174.    plot_text(5+110,150,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  175.    sprintf(foo,"%ld",myctr[4]);
  176.    plot_text(5+70,182,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  177.    z = width * height;
  178.    pcx = (100 * myctr[4]) / z;
  179.    sprintf(foo,"%ld",pcx);
  180.    strcat(foo,"%");
  181.    plot_text(5+110,182,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  182.    sprintf(foo,"%ld",myctr[5]);
  183.    plot_text(5+70,214,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  184.    z = width * height;
  185.    pcx = (100 * myctr[5]) / z;
  186.    sprintf(foo,"%ld",pcx);
  187.    strcat(foo,"%");
  188.    plot_text(5+110,214,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  189.    sprintf(foo,"%ld",myctr[6]);
  190.    plot_text(5+70,246,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  191.    z = width * height;
  192.    pcx = (100 * myctr[6]) / z;
  193.    sprintf(foo,"%ld",pcx);
  194.    strcat(foo,"%");
  195.    plot_text(5+110,246,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  196.    sprintf(foo,"%ld",myctr[7]);
  197.    plot_text(5+70,279,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  198.    z = width * height;
  199.    pcx = (100 * myctr[7]) / z;
  200.    sprintf(foo,"%ld",pcx);
  201.    strcat(foo,"%");
  202.    plot_text(5+110,279,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  203.    sprintf(foo,"%ld",myctr[8]);
  204.    plot_text(5+300,52,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  205.    z = width * height;
  206.    pcx = (100 * myctr[8]) / z;
  207.    sprintf(foo,"%ld",pcx);
  208.    strcat(foo,"%");
  209.    plot_text(5+340,52,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  210.    sprintf(foo,"%ld",myctr[9]);
  211.    plot_text(5+300,85,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  212.    z = width * height;
  213.    pcx = (100 * myctr[9]) / z;
  214.    sprintf(foo,"%ld",pcx);
  215.    strcat(foo,"%");
  216.    plot_text(5+340,85,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  217.    sprintf(foo,"%ld",myctr[10]);
  218.    plot_text(5+300,118,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  219.    z = width * height;
  220.    pcx = (100 * myctr[10]) / z;
  221.    sprintf(foo,"%ld",pcx);
  222.    strcat(foo,"%");
  223.    plot_text(5+340,118,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  224.    sprintf(foo,"%ld",myctr[11]);
  225.    plot_text(5+300,150,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  226.    z = width * height;
  227.    pcx = (100 * myctr[11]) / z;
  228.    sprintf(foo,"%ld",pcx);
  229.    strcat(foo,"%");
  230.    plot_text(5+340,150,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  231.    sprintf(foo,"%ld",myctr[12]);
  232.    plot_text(5+300,182,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  233.    z = width * height;
  234.    pcx = (100 * myctr[12]) / z;
  235.    sprintf(foo,"%ld",pcx);
  236.    strcat(foo,"%");
  237.    plot_text(5+340,182,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  238.    sprintf(foo,"%ld",myctr[13]);
  239.    plot_text(5+300,214,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  240.    z = width * height;
  241.    pcx = (100 * myctr[13]) / z;
  242.    sprintf(foo,"%ld",pcx);
  243.    strcat(foo,"%");
  244.    plot_text(5+340,214,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  245.    sprintf(foo,"%ld",myctr[14]);
  246.    plot_text(5+300,246,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  247.    z = width * height;
  248.    pcx = (100 * myctr[14]) / z;
  249.    sprintf(foo,"%ld",pcx);
  250.    strcat(foo,"%");
  251.    plot_text(5+340,246,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  252.    sprintf(foo,"%ld",myctr[15]);
  253.    plot_text(5+300,279,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  254.    z = width * height;
  255.    pcx = (100 * myctr[15]) / z;
  256.    sprintf(foo,"%ld",pcx);
  257.    strcat(foo,"%");
  258.    plot_text(5+340,279,foo,WHITE,LT_GRAY,JAM2,&topaz11); 
  259.  
  260.        
  261.    {  // handle the user actions here
  262.       struct IntuiMessage *message; // the message the IDCMP sends us
  263.       //struct MenuItem *item;
  264.       //int ctr;
  265.  
  266.       // useful for interpreting IDCMP messages
  267.       UWORD code;
  268.       ULONG class;
  269.       APTR object;
  270.  
  271.       while (TRUE) {
  272.          WaitPort(stats_window->UserPort);
  273.          while (message = GT_GetIMsg(stats_window->UserPort)) {
  274.             code = message->Code;  // MENUNUM
  275.             object = message->IAddress;  // Gadget
  276.             class = message->Class;
  277.             GT_ReplyIMsg(message);
  278.             //if (class==MOUSEBUTTONS && code==SELECTDOWN)
  279.             //   new_terrain(message->MouseX,message->MouseY);
  280.             if (class==GADGETUP) {
  281.                if (object==ok_gad)
  282.                   goto exit_stats_window;
  283.             FI
  284.             if (class==IDCMP_VANILLAKEY && code==13) {
  285.                goto exit_stats_window;
  286.             FI
  287.             if (class==CLOSEWINDOW)
  288.                goto exit_stats_window;
  289.          OD
  290.       OD
  291.    }
  292.    exit_stats_window:
  293.  
  294.  
  295.    // now clean everything up and leave
  296.        rast_port = map_window->RPort;
  297.        CloseWindow(stats_window);
  298.        stats_window = NULL;
  299.        FreeGadgets(context);
  300.        ClearPointer(map_window);
  301.        ModifyIDCMP(map_window,IDCMP_MAPEDIT);
  302. }
  303.  
  304. void do_connect()
  305. {
  306.         struct rtHandlerInfo *handle;
  307.         //int flag=0;
  308.         int ctx, cty;
  309.         int x1=0;
  310.         int y1=0;
  311.         int x2=0;
  312.         int y2=0;
  313.         
  314.    // make sure user doesn't play with the map window now
  315.    SetPointer(map_window,BUSY_POINTER);
  316.    ModifyIDCMP(map_window,NULL);
  317.  
  318.  
  319.    sprintf(foo,"Connecting Cities.\nPlease wait...");
  320.    handle = post_it(foo);      
  321.  
  322.    for (ctx = 0; ctx<=width; ctx++) {
  323.        for (cty = 0; cty<=height; cty++) {
  324.            if (city_hereP(ctx-1,cty-1)) {
  325.                     if(x1==0 && y1==0) {
  326.                         x1 = ctx-1;
  327.                         y1 = cty-1;
  328.                         continue;
  329.                     FI
  330.                     if(x2==0 && y2==0) {
  331.                         x2 = ctx-1;
  332.                         y2 = cty-1;
  333.                         Calc_Path(x1,y1,x2,y2);
  334.                         x1=0;
  335.                         y1=0;
  336.                         x2=0;
  337.                         y2=0;                                       
  338.                     FI                                
  339.            FI
  340.        OD
  341.    OD
  342.  
  343. //   for (ctx = 0; ctx<=height; ctx++) {
  344. //       for (cty = 0; cty<=width; cty++) {
  345. //           if (city_hereP(ctx-1,cty-1)) {
  346. //                    if(x1==0 && y1==0) {
  347. //                        x1 = ctx-1;
  348. //                        y1 = cty-1;
  349. //                        continue;
  350. //                    FI
  351. //                    if(x2==0 && y2==0) {
  352. //                        x2 = ctx-1;
  353. //                        y2 = cty-1;
  354. //                    FI
  355. //                    draw_road(x1,y1,x2,y2);
  356. //                    x1=y1=x2=y2=0;    
  357. //           FI                                       
  358. //       OD
  359. //   OD
  360.  
  361.  
  362.    exit_do_connect:
  363.         ClearPointer(map_window);
  364.         ModifyIDCMP(map_window,IDCMP_MAPEDIT);
  365.         unpost_it(handle);
  366.  
  367. }
  368.  
  369. /***************************************************************
  370. ***** Path Finding Routines  (modified for connect cities) *****
  371. ***************************************************************/
  372. #define REVERSE_DIRECTION(num)  ((num+3)%6)
  373. void  Calc_Path (short orgx, short orgy, short destx, short desty)
  374. {
  375.   int                flag=0;
  376.   int                i, rigor;
  377.   short              Destx, Desty;
  378.   short              targx, targy;
  379.   int                Pickdir, PathCost;
  380.   long               NewCost;
  381.   struct PathNode*   PNode = NULL;
  382.   struct PathNode*   PNode2 = NULL;
  383.   struct PathNode*   WalkNode;
  384.   int                Found;
  385.   // First, we initialize some stuff and check for input errors
  386.   // Set up the globals
  387.   //Type = type;  // One less push and pop on the stack for getting cost
  388.   //PathDiv = rigor;  // Dial up the precision required - 1 to 10
  389.   //if (rigor < 1) rigor = 1;
  390.   //if (rigor > 10) rigor = 10;
  391.   rigor = 1;
  392.   Destx = destx;
  393.   Desty = desty;
  394.   // Clear the return values
  395.   for( i=0; i<MAX_PATH; i++ )  Path[i] = -1;
  396.   // Check for bad inputs
  397.   if( (orgx >= width)||(orgx < 0)||(orgy >= height)||(orgy < 0) ) return;
  398.   if( (destx >= width)||(destx < 0)||(desty >= height)||(desty < 0) ) return;
  399.   // Now, check the direction map
  400.   if( !PathMap ) {
  401.     // Must be the first time this has been called
  402.     // Allocate PathMap, set PathMapX and PathMapY, initialize the
  403.     //    lists.
  404.     PathMap = (int*) malloc( sizeof(int) * width * height );
  405.     if( !PathMap ) return;  // Abort this!
  406.     PathMapX = width;
  407.     PathMapY = height;
  408.     for(i=0; i< (width*height); i++)  PathMap[i] = -1;
  409.   }
  410.   if( (PathMapX != width) || (PathMapY != height) ) {
  411.     // We have started a new game without exitting - the map changed
  412.     PathMap = (int*) malloc( sizeof(int) * width * height );
  413.     if( !PathMap ) return;  // Abort this!
  414.     PathMapX = width;
  415.     PathMapY = height;
  416.     for(i=0; i< (width*height); i++)  PathMap[i] = -1;
  417.   }
  418.   // Initialize both lists, just to be sure we're starting good.
  419.   NewList ((struct List*)&OpenList);
  420.   NewList ((struct List*)&DoneList);
  421.   
  422.    // To begin, insert the starting node into the OpenList
  423.   PNode = AllocVec( (long)sizeof(*PNode ), MEMF_CLEAR );
  424.   if( !PNode ) return; // Abort!  Can't get memory!
  425.   // We will start from the destination, so recording the path after
  426.   //   will be easier.
  427.   PNode->x = destx;
  428.   PNode->y = desty;
  429.   PNode->cost = 0; 
  430.   // Here we use the rigor to define how well to search for paths
  431.   // Underestimating is best - makes us check more possible paths 
  432.   //   but it is slower.  Rigor goes from 1 to 10, with 1 being the
  433.   //   most rigorous and 10 the least (it will settle on less optimal
  434.   //   paths).
  435.   PNode->eta = AI5_GetDist( orgx, orgy, destx, desty ) * 10 * rigor;
  436.   AddHead((struct List *)&OpenList,(struct Node *)PNode);
  437.   // Now, enter the while loop until we are done
  438.   while( !emptylistP( &OpenList ) ) {
  439.     // Change - make a new routine to get the best bet out of OpenList
  440.     PNode = AI5_OpenListGetBest();
  441.     // Put it in the DoneList - we are visiting it now
  442.     AddTail((struct List*)&DoneList,(struct Node*)PNode);
  443.     // Check for destination
  444.     if( (PNode->x == orgx) && (PNode->y == orgy) )  break; 
  445.     // Not there yet, so let's look at the hexes around it
  446.     // Pick a random direction to start with
  447.     Pickdir = RangeRand( 6L ); // Gets us 0-5
  448.     i = Pickdir; // To start us off on Pickdir
  449.     do {
  450.       // Get the hex in that direction
  451.       if( AI1_calc_dir (i, PNode->x, PNode->y, &targx, &targy) != -1 ) {
  452.         // Find the cost to get to the new hex
  453.         NewCost = AI5_GetCost( PNode->x, PNode->y);
  454.         // Can we even go here?
  455.         if( NewCost < 0 ) {
  456.           i++;
  457.           if( i > 5 ) i=0;         
  458.           continue;
  459.         }
  460.  
  461.         PNode2 = AllocVec( (long)sizeof(*PNode2 ), MEMF_CLEAR );
  462.         // On memory problem, get out
  463.         if( !PNode2 ) {
  464.           i++;
  465.           if( i > 5 ) i=0;
  466.           continue;
  467.         }
  468.         PNode2->x = targx;
  469.         PNode2->y = targy;
  470.         PNode2->cost = PNode->cost + NewCost;
  471.         // We use the *60 here to estimate that we will spend 60/hex
  472.         PNode2->eta = AI5_GetDist( targx, targy, orgx, orgy )*10*rigor;
  473.  
  474.         // If not marked on the map already, mark it and place it in OpenList
  475.         if( PathMap[ targy * width + targx ] == -1 ) {
  476.           PathMap[ targy * width + targx ] = REVERSE_DIRECTION(i);
  477.               AddTail( (struct List*)&OpenList, (struct Node*)PNode2 );
  478.         }
  479.         // else, try to find it in the OpenList, and replace it ifs cost
  480.         //    is greater (took more to get there) and mark it again.
  481.         else {
  482.           Found = FALSE;
  483.           WalkNode = (struct PathNode*)OpenList.mlh_Head;
  484.           for(; WalkNode->pnode.mln_Succ; WalkNode = 
  485.             (struct PathNode*)WalkNode->pnode.mln_Succ) {
  486.             if( (WalkNode->x == PNode2->x) && (WalkNode->y == PNode2->y) ) {
  487.               // found the matching node
  488.               if( WalkNode->cost > PNode2->cost ) {
  489.                 // replace it - classic extraction from a double linked list
  490.                 Remove( (struct Node*)WalkNode );
  491.                 FreeVec( WalkNode );
  492.                 WalkNode = NULL; // Just to make sure
  493.                 Found = TRUE;
  494.                 AddTail( (struct List*)&OpenList, (struct Node*)PNode2 );
  495.                 // Mark the spot
  496.                 PathMap[ targy * width + targx ] = REVERSE_DIRECTION(i);
  497.                   }
  498.             }
  499.           } // End for loop
  500.           // if we didn't find it, forget it.
  501.           if( Found == FALSE ) FreeVec( PNode2 );
  502.           PNode2 = NULL; // Just to make sure.
  503.         } // End else was already marked
  504.       } // End if there is a hex in this direction
  505.       // increment our direction
  506.       i++;
  507.       if( i > 5 ) i=0;
  508.     } while( i != Pickdir); // End do-while loop of directions 
  509.   } // End while OpenList not empty
  510.  
  511.   PathLength = 0;
  512.   PathCost = -1;
  513.   // OK, now check that we have a path
  514.   if( (PNode->x == orgx) && (PNode->y == orgy) && 
  515.     (PNode->cost > 0) && (PNode->eta == 0) ) {
  516.     // we found a path!
  517.     // Record it.
  518.     targx = orgx;
  519.     targy = orgy;
  520.     for(i=0; i<MAX_PATH; i++) {
  521.       // Record the first steps
  522.       Path[i] = PathMap[ targy * width + targx ];
  523.       PathLength++;
  524.       // Look!  This routine even works on its own parameters!
  525.       if( AI1_calc_dir (Path[i], targx, targy, &targx, &targy) == -1 ) {
  526.          break;
  527.       }
  528.       flag = flag | ROAD;     // add road to this hex
  529.       put_flags(t_grid,targy,targx,flag);  
  530.       ME_draw_roads(targy,targx);
  531.       if( (targx == destx) && (targy == desty) ) {
  532.         // we made it! exit!
  533.         break;
  534.       }
  535.     }
  536.     // And record the total cost of moving along the path
  537.     //PathCost = PNode->cost;
  538.   }
  539.   // else nothing - we already cleared the path to nothing
  540.  
  541.   // Erase the marked up map for the next person
  542.   for( WalkNode = (struct PathNode*)OpenList.mlh_Head; WalkNode->pnode.mln_Succ; 
  543.        WalkNode = (struct PathNode*)WalkNode->pnode.mln_Succ ) {
  544.     PathMap[ WalkNode->y * width + WalkNode->x ] = -1;
  545.   }
  546.   // For debugging / timing count the nodes here - easier to see
  547.   i = count_nodes( &OpenList );
  548.   for( WalkNode = (struct PathNode*)DoneList.mlh_Head; WalkNode->pnode.mln_Succ; 
  549.        WalkNode = (struct PathNode*)WalkNode->pnode.mln_Succ ) {
  550.     PathMap[ WalkNode->y * width + WalkNode->x ] = -1;
  551.   }
  552.  
  553.   // Cleanup both lists
  554.   nuke_list( &OpenList );
  555.   nuke_list( &DoneList );
  556.  
  557.  
  558.   return;
  559. }
  560.  
  561.  
  562.  
  563.  
  564. /**************************\
  565. |   END OF MAP_EDITOR2.C   |
  566. \**************************/
  567.  
  568.